package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Details;
import cn.wolfcode.crm.domain.Directory;
import cn.wolfcode.crm.mapper.DetailsMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDetailsService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class DetailsServiceImpl implements IDetailsService {
    @Autowired
    private DetailsMapper mapper;

    public List<Details> selectAll() {
        return mapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        int count = mapper.query4Count(qo);
        if (count > 0) {
            return new PageResult(count, mapper.query4List(qo));
        }
        return new PageResult(count, Collections.EMPTY_LIST);
    }

    public void updateByPrimaryKey(Details record, Directory sn) {
        /*mapper.updateByPrimaryKey(record,sn);*/
        mapper.updateByRecordAndSn(record,sn);
    }

    @Override
    public Details getByName(String name) {
        return null;
    }


    public void insert(Details record, Directory sn) {

        mapper.insertByRecordAndSn(record,sn);
    }

    @Override
    public void changeState(Long id) {

    }

    @Override
    public Long selectByUserName(String name) {
        return null;
    }


    public Details selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Details> getDictionariesSnByDetails(String dictionariesSn) {
        return mapper.getDictionariesSnByDetails(dictionariesSn);
    }

    @Override
    public void deleteById(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public Details selectDetailsByid(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<Details> getPlanDetails(String sn) {
        sn="plan";
        return mapper.getPlanDetails(sn);
    }


}
